package fhp.hlhj.giantfold.customView

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.CompoundButton
import android.widget.PopupWindow
import android.widget.RelativeLayout
import fhp.hlhj.giantfold.R
import kotlinx.android.synthetic.main.gain_pop.view.*

/**
 * author: FHP
 * data: on 2017\11\28 0028 16:21
 * E-Mail: 103945089@qq.com
 */
class GainPop(private var context: Context,private val gainPopListener: GainPopListener) :PopupWindow() {
    private lateinit var rootView:View
    init {
        initPop()
        setPop()
    }

    private fun setPop() {
        rootView=LayoutInflater.from(context).inflate(R.layout.gain_pop,null)
        contentView=rootView

        rootView.availableCB.setOnCheckedChangeListener { buttonView, isChecked ->
            if (isChecked){
                rootView.gainCB.isChecked=false
                rootView.spendCB.isChecked=false
                rootView.getCashCB.isChecked=false
                gainPopListener.available()
                dismiss()
            }
        }
        rootView.gainCB.setOnCheckedChangeListener { buttonView, isChecked ->
            if (isChecked){
                rootView.availableCB.isChecked=false
                rootView.spendCB.isChecked=false
                rootView.getCashCB.isChecked=false
                gainPopListener.gain()
                dismiss()
            }
        }
        rootView.spendCB.setOnCheckedChangeListener { buttonView, isChecked ->
            if (isChecked){
                rootView.availableCB.isChecked=false
                rootView.gainCB.isChecked=false
                rootView.getCashCB.isChecked=false
                gainPopListener.spend()
                dismiss()
            }
        }
        rootView.getCashCB.setOnCheckedChangeListener { buttonView, isChecked ->
            if (isChecked){
                rootView.availableCB.isChecked=false
                rootView.gainCB.isChecked=false
                rootView.spendCB.isChecked=false
                gainPopListener.getcash()
                dismiss()
            }
        }

    }

    private fun initPop() {
        this.width=RelativeLayout.LayoutParams.MATCH_PARENT
        this.height=RelativeLayout.LayoutParams.WRAP_CONTENT


//        this.isFocusable=true

    }

    interface GainPopListener{
        fun available()
        fun gain()
        fun spend()
        fun getcash()
    }
}